#include "SQList.h"
void SLInit(SL* ps)
{
	ps->a = NULL;
	ps->size = 0;
	ps->capacity = 0;
}
void SLDestroy(SL* ps)
{
	assert(ps);
	free(ps->a);
	ps->a = NULL;
	ps->size = 0;
	ps->capacity = 0;
}
void SLCheckCapacity(SL* ps)
{
	assert(ps);
	if (ps->size == ps->capacity)
	{
		int capacity_tmp;
		if (ps->capacity == 0)
		{
			capacity_tmp = INIT_CAPACITY;
		}
		else
		{
			capacity_tmp = 2 * ps->capacity;
		}
		SLDataType* a_tmp = (SLDataType*)realloc(ps->a, capacity_tmp * sizeof(SLDataType));
		if (a_tmp)
		{
			ps->a = a_tmp;
			ps->capacity = capacity_tmp;
		}
		else
		{
			perror("ʧ");
			exit(1);
		}
	}
}
void SLPushBack(SL* ps, SLDataType x)
{
	assert(ps);
	SLCheckCapacity(ps);
	ps->a[ps->size] = x;
	ps->size++;
}
void SLErase(SL* ps, int pos)
{
	assert(ps->a);
	assert(pos >= 0 && pos < ps->size);
	memmove(ps->a + pos, ps->a + pos + 1, (ps->size - pos - 1) * sizeof(SLDataType));
	ps->size--;
}